from flask import Flask
from flask_cors import CORS
from dotenv import load_dotenv
import os
from extensions import db
from routes import register_routes

# 加载环境变量
load_dotenv()

# 创建Flask应用
app = Flask(__name__)

# 配置CORS
CORS(app)

# 配置数据库
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 初始化数据库扩展
db.init_app(app)

# 创建数据库表
with app.app_context():
    db.create_all()

# 注册路由
register_routes(app)

if __name__ == '__main__':
    app.run(debug=True, port=5001)